package com.authine.cloudpivot.ext.applicationservice;


import com.alibaba.cola.dto.RequestContext;
import com.authine.cloudpivot.ext.constants.ModelConst;
import com.authine.cloudpivot.ext.constants.PlatformConst;
import com.authine.cloudpivot.ext.dto.JobDto;
import com.authine.cloudpivot.ext.dto.base.Ids;
import com.authine.cloudpivot.ext.enums.system.TriggerMetaStatusEnum;
import com.authine.cloudpivot.ext.utils.BoServiceUtils;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;

import javax.ws.rs.POST;
import javax.ws.rs.Path;

import java.util.Map;

import static com.authine.hermes.app.launcher.service.ApplicationServiceFoundation.CUSTOM_SERVICE;

@Path("GoldenTaxJobExecutor")
@Slf4j
public class GoldenTaxJobExecutor {



    @Path("execute")
    @POST
    @Operation(summary = "发票申请单批量反写", description = "发票申请单列表，待开票上面的批量反写功能", tags = CUSTOM_SERVICE)
    public void execute(JobDto jobDto){
        // 设置token认证信息
        RequestContext.get().setCorpLoginId(PlatformConst.corpLoginId);
        RequestContext.get().setLoginId(PlatformConst.loginId);
        RequestContext.get().setLoginName(PlatformConst.loginName);
        log.info("================开始金税开票信息反写任务");

        InvoiceApplyController invoiceApplyController = new InvoiceApplyController();
        invoiceApplyController.goldenTaxConfirmInvoice(new Ids());

        // 修改任务触发器状态为已执行
        Map<String,Object> triggerMetaMap = com.google.common.collect.Maps.newHashMap();
        triggerMetaMap.put("id", jobDto.getTriggerMetaId());
        triggerMetaMap.put("trigger_status", TriggerMetaStatusEnum.EXECUTED.id);
        BoServiceUtils.updateMainBo(ModelConst.T_TRIGGER_META, triggerMetaMap);

        // 清除登录信息
        RequestContext.clear();
    }
}
